﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TimServerSDK.Account.Dtos;
using TimServerSDK.Core;

namespace TimServerSDK.Accounts
{
    public class AccountTimServerApi : AbstractTimServerApi, IAccountTimServerApi
    {
        protected override string ServiceName { get; } = "im_open_login_svc";


        public AccountTimServerApi(IRestClientProvider restClientProvider) : base(restClientProvider)
        {

        }

        public Task<TimServerResult> ImportAsync(string userId, string nick = null, string faceUrl = null)
        {
            return PostAsync<TimServerResult>("account_import", new
            {
                UserID = userId,
                Nick = nick,
                FaceUrl = faceUrl
            });
        }

        public Task<ImportAccountResultDto> MultiImportAsync(string[] accounts)
        {
            return PostAsync<ImportAccountResultDto>("multiaccount_import", new
            {
                Accounts = accounts
            });
        }

        public Task<TimServerResultResultItem<List<CheckAccountResultItemDto>>> DeleteAsync(string[] userIds)
        {
            var DeleteItem = userIds.Select(UserID =>
            {
                return new
                {
                    UserID
                };
            }).ToArray();

            return PostAsync<TimServerResultResultItem<List<CheckAccountResultItemDto>>>("account_delete", new
            {
                DeleteItem
            });
        }

        public Task<TimServerResultResultItem<List<CheckAccountResultItemDto>>> CheckAsync(string[] userIds)
        {
            var CheckItem = userIds.Select(UserID =>
            {
                return new
                {
                    UserID
                };
            }).ToArray();

            return PostAsync<TimServerResultResultItem<List<CheckAccountResultItemDto>>>("account_check", new
            {
                CheckItem
            });
        }

        public Task<TimServerResult> KickAsync(string userId)
        {
            return PostAsync<TimServerResult>("kick", new
            {
                UserID = userId
            });
        }
    }
}
